package com.movie.controller;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.movie.comm.utils.PageData;
import com.movie.dao.UserDao;
import com.movie.dao.impl.MUserDaoImpl;
import com.movie.entity.Message;

/**
 * 
* @ClassName: UserAdminAction 
* @Description: 后台用户删除业务
* @author 左岩
* @date 2018年12月7日 上午7:24:26 
*
 */
@WebServlet(urlPatterns="/admin/userdel")
public class UserAdminAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PageData pageData = new PageData(request);
		UserDao userDao = new MUserDaoImpl();
		boolean isSuccess = userDao.delUserById(pageData);
		OutputStream out = response.getOutputStream();
		if(isSuccess){
			Gson gson = new Gson();
			Message message = new Message();
			message.setCode(1);
			message.setMsg("删除成功！");
			String json = gson.toJson(message);
			out.write(json.getBytes("UTF-8"));
			out.flush();
			
		}
		else{
			Gson gson = new Gson();
			Message message = new Message();
			message.setCode(0);
			message.setMsg("删除失败！");
			String json = gson.toJson(message);
			out.write(json.getBytes("UTF-8"));
			out.flush();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
